package com.aft.terra.common.interceptor;

import com.aft.terra.common.utils.RedisKit;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;

public class CallBackLockInterceptor implements Interceptor {

	public void intercept(Invocation invocation) {
		Controller controller = invocation.getController();
		String orderCode = "";
		if (StrKit.notBlank(controller.getPara("ORDERID"))) {// 建行银联回调返回订单编号
			orderCode = controller.getPara("ORDERID");
		} 
		if (StrKit.notBlank(orderCode)) {
			String lockKey = RedisKit.getCache().get(orderCode);
			if (StrKit.notBlank(lockKey)) {// lockKey不是空，为正在执行回调
				return;
			} else {
				RedisKit.getCache().set(orderCode, orderCode);
				invocation.invoke();
			}
		} else {
			return;
		}
	}
}
